package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAutoCodePart;
import com.ruoyi.system.service.ISysAutoCodePartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 编码生成规则组成Controller
 * 
 * @author ruoyi
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/system/part")
@Api(tags = "编码生成规则组成接口")
public class SysAutoCodePartController extends BaseController
{
    @Autowired
    private ISysAutoCodePartService sysAutoCodePartService;

    /**
     * 查询编码生成规则组成列表
     */
    @PreAuthorize("@ss.hasPermi('system:part:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询编码生成规则组成列表")
    public TableDataInfo list(SysAutoCodePart sysAutoCodePart)
    {
        startPage();
        List<SysAutoCodePart> list = sysAutoCodePartService.selectSysAutoCodePartList(sysAutoCodePart);
        return getDataTable(list);
    }

    /**
     * 导出编码生成规则组成列表
     */
    @PreAuthorize("@ss.hasPermi('system:part:export')")
    @Log(title = "编码生成规则组成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAutoCodePart sysAutoCodePart)
    {
        List<SysAutoCodePart> list = sysAutoCodePartService.selectSysAutoCodePartList(sysAutoCodePart);
        ExcelUtil<SysAutoCodePart> util = new ExcelUtil<SysAutoCodePart>(SysAutoCodePart.class);
        util.exportExcel(response, list, "编码生成规则组成数据");
    }

    /**
     * 获取编码生成规则组成详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:part:query')")
    @GetMapping(value = "/{ruleId}")
    @ApiOperation(value = "获取编码生成规则组成详细信息")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(sysAutoCodePartService.selectSysAutoCodePartByRuleId(ruleId));
    }

    /**
     * 新增编码生成规则组成
     */
    @PreAuthorize("@ss.hasPermi('system:part:add')")
    @ApiOperation(value = "新增编码生成规则组成")
    @Log(title = "编码生成规则组成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAutoCodePart sysAutoCodePart)
    {
        return toAjax(sysAutoCodePartService.insertSysAutoCodePart(sysAutoCodePart));
    }

    /**
     * 批量新增编码生成规则组成
     */
    @PreAuthorize("@ss.hasPermi('system:part:add')")
    @ApiOperation(value = "批量新增编码生成规则组成")
    @Log(title = "编码生成规则组成", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batch(@RequestBody List<SysAutoCodePart> sysAutoCodePart)
    {
        return toAjax(sysAutoCodePartService.batchSysAutoCodePart(sysAutoCodePart));
    }

    /**
     * 修改编码生成规则组成
     */
    @PreAuthorize("@ss.hasPermi('system:part:edit')")
    @ApiOperation(value = "修改编码生成规则组成")
    @Log(title = "编码生成规则组成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAutoCodePart sysAutoCodePart)
    {
        return toAjax(sysAutoCodePartService.updateSysAutoCodePart(sysAutoCodePart));
    }

    /**
     * 删除编码生成规则组成
     */
    @PreAuthorize("@ss.hasPermi('system:part:remove')")
    @ApiOperation(value = "删除编码生成规则组成")
    @Log(title = "编码生成规则组成", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(sysAutoCodePartService.deleteSysAutoCodePartByRuleIds(ruleIds));
    }
}
